﻿

using Controller.i18n.entity;
using HBase;
using hCommand;
using hCommand.open;
using hconnect;
using Persistence;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace Controller
{
    public class KanbanAllocateJob60 : ZtTask
    {
        protected ICoreStockServer stockServer = WMSDalFactray.getDal<ICoreStockServer>();
        protected ICoreTaskServer taskServer = WMSDalFactray.getDal<ICoreTaskServer>();

        protected IItemServer itemServer = WMSDalFactray.getDal<IItemServer>();
        protected int taskNo;
        public KanbanAllocateJob60()
        {
            time = 200;
        }

        public override bool excute()
        {
            NewMethod(11);
            NewMethod(14);
            NewMethod(21);
            NewMethod(24);
            NewMethod(31);
            NewMethod(32);
            NewMethod(41);
            NewMethod(42);
            LedInfoDisplay();
            return true;
        }

        private void LedInfoDisplay()
        {
            List<TaskCrane> taskCranes = MyCache.getList<TaskCrane>();
            foreach (var item in taskCranes)
            {
                if (item.status > 11 && item.status < 80)
                {
                    CoreTask coreTask = taskServer.getById<CoreTask>(item.completeId);
                    if (coreTask == null)
                    {
                        return;
                    }
                    CoreStock coreStock = stockServer.getById<CoreStock>(coreTask.stockId);
                    if (coreStock == null)
                    {
                        return;
                    }
                    CoreItem coreItem = itemServer.getById<CoreItem>(coreStock.dItemId);
                    if (coreItem == null)
                    {
                        return;
                    }
                    if (!I18nConfig.isLoc(item.des))
                    {
                        KanBanConnect conn = TaskPool.get<KanBanConnect>(item.des + 100);
                        conn.LedFormatInfo("出库", $"{coreItem.code}-{coreItem.name}-{coreStock.dCount}");
                    }

                    if (!I18nConfig.isLoc(item.src))
                    {
                        KanBanConnect conn = TaskPool.get<KanBanConnect>(item.src + 100);
                        conn.LedFormatInfo("入库", $"{coreItem.code}-{coreItem.name}-{coreStock.dCount}");
                    }
                }
            }
        }

        private void NewMethod(int stn)
        {
            List<TaskCrane> taskCranes = MyCache.getList<TaskCrane>();
            TaskCrane taskCrane = taskCranes.Where(x=>x.des == stn || x.src == stn).FirstOrDefault();
            if (taskCrane == null)
            {
                KanBanConnect conn = TaskPool.get<KanBanConnect>(stn + 100);
              //  conn.clearLine1();
            }
        }
    }
}
